// pagesCollect/pages/reg/step2.js
const app = getApp()
import { getStorage } from "../../../utils/localStorage"
import { registration } from "../../../api/collect"

Page({
  data: {
    navData: {
      title: '',
      level: 10
    },
    form: {
      realName: '',
      phoneNumber: '',
      team: '',
      speciality: ''
    },
    userInfo:{},
    navHeight: 32,
    navTop: 48,
    sureDisclaimer: false,
    disclaimerShow:false,
    disclaimerStr:''
  },
  onLoad() {
    let userInfo = getStorage('user');
    this.setData({
      navHeight: app.globalData.navHeight, //导航栏高度
      navTop: app.globalData.navTop, //导航栏距顶部距离
      ['form.realName']:userInfo.realName||'',
      ['form.phoneNumber']:userInfo.phoneNumber||''
    });
    this.getMzsm()
  },
  getMzsm(){
    app.getDict('rule_statement').then(res => {
      console.log(res)
      let ruleStatement = res.data;
      ruleStatement.forEach(item=>{
        if(item.dictValue=='tygzcmzsm'){
          this.setData({
            disclaimerStr:item.content
          })
        }
      })
    })
  },
  sure(){
    let {form}= this.data;
    if(!form.realName||!form.phoneNumber||!form.team||!form.speciality){
      wx.showToast({
        icon:'none',
        title: '请填写完整信息',
      })
      return false;
    }
    if(!this.data.sureDisclaimer){
      wx.showToast({
        icon:'none',
        title: '请先确认阅读免责声明',
      })
      return false;
    } 
    
    registration(form).then(res=>{
      console.log(res)
      wx.navigateTo({
        url: '/pagesCollect/pages/reg/step3',
      })
    })
    
  },
  intChg(e) {
    let value = e.detail.value,
      key = e.currentTarget.dataset.key;
    this.setData({
      ['form.' + key]: value
    })
  },
  disclaimerStateChg() {
    this.setData({
      sureDisclaimer: !this.data.sureDisclaimer
    })
  },
  disclaimerChg(e) {
    let state = e.currentTarget.dataset.state;
    this.setData({
      disclaimerShow: state == '1' ? true : false
    })
  }
})